package com.thinkis.common.utils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.thinkis.common.mapper.JsonMapper;

import java.util.LinkedHashMap;

/**
 * Created with IntelliJ IDEA
 * Created By jauddy
 * Date: 2019/7/5
 * Time: 13:11
 */
public class AjaxJson {
    private boolean success = true;// 是否成功
    private String errorCode = "-1";//错误代码
    private String msg = "操作成功";// 提示信息
    private LinkedHashMap<String, Object> body = new LinkedHashMap<String, Object>();//封装json的map

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public LinkedHashMap<String, Object> getBody() {
        return body;
    }

    public void setBody(LinkedHashMap<String, Object> body) {
        this.body = body;
    }

    @JsonIgnore//返回对象时忽略此属性
    public String getJsonStr() {//返回json字符串数组，将访问msg和key的方式统一化，都使用data.key的方式直接访问。

        String json = JsonMapper.getInstance().toJson(this);
        return json;
    }
}
